Hridaya stores all market data in a SQLite database (market_data.db) with four tables, each capturing different aspects of market activity. This guide provides practical SQL queries for analyzing your data.
SELECT date(time) AS day, AVG(price) AS avg_price, MIN(price) AS low, MAX(price) AS high, SUM(volume) AS total_volumeFROM price_historyWHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND time > datetime('now', '-30 days')GROUP BY date(time)ORDER BY day DESC;
WITH avg_price AS ( SELECT AVG(price) AS mean FROM price_history WHERE market_hash_name = 'AK-47 | Redline (Field-Tested)')SELECT time, price, volume, ((price - mean) / mean * 100) AS percent_above_avgFROM price_history, avg_priceWHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND price > mean * 1.2ORDER BY time DESC;
SELECT date(time) AS day, AVG(price) AS daily_avg, AVG(AVG(price)) OVER ( ORDER BY date(time) ROWS BETWEEN 6 PRECEDING AND CURRENT ROW ) AS moving_avg_7dayFROM price_historyWHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND time > datetime('now', '-60 days')GROUP BY date(time)ORDER BY day;
SELECT market_hash_name, MAX(timestamp) AS last_update, lowest_price, median_price, volumeFROM price_overviewGROUP BY market_hash_nameORDER BY volume DESC;
SELECT market_hash_name, MIN(price) AS low, MAX(price) AS high, MAX(price) - MIN(price) AS range, (MAX(price) - MIN(price)) / AVG(price) * 100 AS volatility_pctFROM price_historyWHERE time > datetime('now', '-24 hours')GROUP BY market_hash_nameORDER BY volatility_pct DESC;
Find most actively traded items in the last 24 hours:
SELECT market_hash_name, SUM(volume) AS total_volume, AVG(price) AS avg_priceFROM price_historyWHERE time > datetime('now', '-24 hours')GROUP BY market_hash_nameORDER BY total_volume DESCLIMIT 10;
WITH avg_volume AS ( SELECT AVG(volume) AS mean_vol FROM price_history WHERE market_hash_name = 'AK-47 | Redline (Field-Tested)')SELECT time, volume, price, (volume / mean_vol) AS volume_ratioFROM price_history, avg_volumeWHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND volume > mean_vol * 3ORDER BY time DESC;
WITH recent AS ( SELECT price FROM price_overview WHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' ORDER BY timestamp DESC LIMIT 1),week_avg AS ( SELECT AVG(price) AS avg_price FROM price_history WHERE market_hash_name = 'AK-47 | Redline (Field-Tested)' AND time > datetime('now', '-7 days'))SELECT recent.price AS current_price, week_avg.avg_price AS week_avg, ((recent.price - week_avg.avg_price) / week_avg.avg_price * 100) AS momentum_pctFROM recent, week_avg;
Use indexes effectively: The database is pre-indexed on (market_hash_name, timestamp DESC). Always include market_hash_name in your WHERE clause for optimal performance.
.mode column -- Format output in columns.headers on -- Show column headers.timer on -- Show query execution time.schema price_history -- Show table structure.tables -- List all tables.quit -- Exit SQLite